/**
 * Created by Administrator on 2017/4/14.
 */
/*滚动*/
$(function(){
    var page = {'pageNum':1,'pageSize':10};
    //var url = 'http://172.16.2.66:8080/oneTalkOnline/keep/load_actor_online';
    var headerImg,nickName,age,label,bwh,height,priceGold,photoImg,constellation,likeType,followerCount,aId;
    /*初始化*/
    var counter = 0; /*计数器*/
    var pageStart = 0; /*offset*/
    var pageSize =10; /*size*/
    var isEnd = false;
    /*首次加载*/
    dataJson(pageStart, pageSize);
    //监听
    $(window).scroll(function(){
       if(isEnd == true){

         }
        // 当滚动到最底部以上100像素时， 加载新内容
        // 核心代码
        if($(document).height() - $(this).scrollTop()- $(this).height() <100){
            page.pageNum++;
            dataJson(pageStart, pageSize);
        }
    })
    function dataJson(offset,size) {
        var url =ACTOR_LIST;
        var time = new Date().getTime();
        console.log(time);
        //var page = {'pageNum':1,'pageSize':10};
        //console.log(page.pageNum);
       var xhr= $.ajax({
            url: url,
            type: 'POST',
            dataType:'json',
            data:JSON.stringify(page),
            beforeSend: function (xhr) {
                xhr.setRequestHeader("ts", time);
                xhr.setRequestHeader("mn", "3");
                xhr.setRequestHeader("chid", "0");
                xhr.setRequestHeader("version","1.0");
                xhr.setRequestHeader("sign", $.md5('ts='+ time +'&mn=3&chid=0&version=1.0&param='+JSON.stringify(page)))
            },
            async: false,
            cache: false,
            contentType: 'application/json;charset=UTF-8',
            success: function (data) {
                 var sum = data.data.length;

                console.log(data);
                var dataContain = document.getElementById('zhuboList').innerHTML;

                template.registerFunction('getImageUrl', function (res) {

                    if(!res) return ;
                    var resultData = JSON.parse(res);

                    for(var i=0;i<resultData.length;i++){
                        if(resultData[i].type == 1){
                            return resultData[i].data.url;
                            break;
                        }
                    }

                });
                var html = template(dataContain, data);
                $("#h-main").append(html);
                if(sum - offset < size ){
                    size = sum - offset;
                }
            },
            error:function(res){
                console.log(res);
            }
        });
        console.log(page.pageNum);
        console.log(size);
        //if(size == page.pageSize){
        //    console.log(size == page.pageSize);
        //     xhr.abort();
        //    return;
        //}
        //console.log(info.length);
        /*跳转到指定页*/
      /*  $(".information").bind('click',function(){
            var aid;
            //console.log( $(this).data('type'));
            aid = $(this).data('type');
            window.location.href = "anchor.html"+"?aid="+aid;
        })*/


    }
});
/*
;(function(w,$){

    var loadmore = {
        */
/*单页加载更多 通用方法
         *
         * @param callback 回调方法
         * @param config 自定义参数
         * *//*

        get : function(callback, config){
            var config = config ? config : {}; */
/*防止未传参数报错*//*


            var counter = 0; */
/*计数器*//*

            var pageStart = 0;
            var pageSize = config.size ? config.size : 10;

            */
/*默认通过点击加载更多*//*

         */
/*   $(document).on('click', '.js-load-more', function(){
                counter ++;
                pageStart = counter * pageSize;

                callback && callback(config, pageStart, pageSize);
            });
*//*

            */
/*通过自动监听滚动事件加载更多,可选支持*//*

            config.isEnd = false; */
/*结束标志*//*

            config.isAjax = false; */
/*防止滚动过快，服务端没来得及响应造成多次请求*//*

            $(window).scroll(function(){

                */
/*是否开启滚动加载*//*

                if(!config.scroll){
                    return;
                }

                */
/*滚动加载时如果已经没有更多的数据了、正在发生请求时，不能继续进行*//*

                if(config.isEnd == true || config.isAjax == true){
                    return;
                }

                */
/*当滚动到最底部以上100像素时， 加载新内容*//*

                if ($(document).height() - $(this).scrollTop() - $(this).height()<100){
                    console.log('加载');
                    counter ++;
                    pageStart = counter * pageSize;

                    callback && callback(config, pageStart, pageSize);
                }
            });

            */
/*第一次自动加载*//*

            callback && callback(config, pageStart, pageSize);
        }

    };

    $.loadmore = loadmore;
})(window, window.jQuery || window.Zepto);
var page = {'pageNum':1,'pageSize':10};
function getData(config, offset,size){
    config.isAjax = true;
    var url =ACTOR_LIST;
    var time = new Date().getTime();
    //console.log(page.pageNum);
    var xhr= $.ajax({
        url: url,
        type: 'POST',
        dataType:'json',
        data:JSON.stringify(page),
        beforeSend: function (xhr) {
            xhr.setRequestHeader("ts", time);
            xhr.setRequestHeader("mn", "3");
            xhr.setRequestHeader("chid", "0");
            xhr.setRequestHeader("version","1.0");
            xhr.setRequestHeader("sign", $.md5('ts='+ time +'&mn=3&chid=0&version=1.0&param='+JSON.stringify(page)))
        },
        async: false,
        cache: false,
        contentType: 'application/json;charset=UTF-8',
        success: function (data) {
            var sum = data.data.length;
            if(sum - offset < size ){
                size = sum - offset;
            }

            var dataContain = document.getElementById('zhuboList').innerHTML;

            template.registerFunction('getImageUrl', function (res) {

                if(!res) return ;
                var resultData = JSON.parse(res);

                for(var i=0;i<resultData.length;i++){
                    if(resultData[i].type == 1){
                        return resultData[i].data.url;
                        break;
                    }
                }

            });
            var html = template(dataContain, data);

            $("#h-main").append(html);
            page.pageNum++;
            */
/*隐藏more*//*

            if ( (offset + size) >= sum){
                $(".js-load-more").show();
                config.isEnd = true; */
/*停止滚动加载请求*//*

                config.isAjax = false;
                //提示没有了
            }else{

                $(".js-load-more").hide();
            }

        },
        error:function(res){
            console.log(res);
        }
    })
}
*/
